<?php /* SVN: $Id: admin_index.ctp 2903 2010-09-02 11:57:31Z sakthivel_135at10 $ */ ?>
<div class="projectFunds index js-response">
<?php if(empty($this->request->params['named']['view_type'])) : ?>
<ul class="filter-list-block clearfix">
<?PHP
                         if($is_wallet_enabled)
                           {
                              $project_status = "Refunded";
                             }

                           else
                           {
                             $project_status = "Voided";
                           }
?>

<?PHP
       if(!$is_wallet_enabled)
       {
?>
        <li <?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'authorized') { echo 'class="active"';} ?>><span class="blue-block" title="<?php echo __l('Authorized'); ?>"><?php echo $this->Html->link($this->Html->cInt($authorized_count,false).'<span>' .__l('Authorized'). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'authorized'), array('escape' => false));?></span> </li>
        <li <?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'captured') { echo 'class="active"';} ?>><span class="red-block" title="<?php echo __l('Captured'); ?>"><?php echo $this->Html->link($this->Html->cInt($captured_count,false).'<span>' .__l('Captured'). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'captured'), array('escape' => false));?></span> </li>
        <li <?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'voided') { echo 'class="active"';} ?>><span class="green-block" title="<?php echo __l('Voided'); ?>"><?php echo $this->Html->link($this->Html->cInt($voided_count,false).'<span>' .__l('Voided'). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'voided'), array('escape' => false));?></span> </li>
        <li <?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'failed') { echo 'class="active"';} ?>><span class="green-block" title="<?php echo __l('Failed'); ?>"><?php echo $this->Html->link($this->Html->cInt($failed_count,false).'<span>' .__l('Failed'). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'failed'), array('escape' => false));?></span> </li>
<?PHP
       }
?>
</ul>
<!--<ul class="fund inbox-option js-pagination clearfix">
    <li class="content-info grid_left"><?php echo sprintf(__l('Total Pledged: %s'),Configure::read('site.currency') . $this->Html->cCurrency($total_pledge)); ?></li>
    <li class="content-info grid_left"><?php echo sprintf(__l('Total Paid: %s'),Configure::read('site.currency') . $this->Html->cCurrency($total_paid)); ?></li>
    <li class="content-info grid_left"><?php echo sprintf(__l('Total Refund: %s'),Configure::read('site.currency') . $this->Html->cCurrency($total_refunded)); ?></li>
</ul>-->
<div class="page-count-block clearfix">
	    <div class="grid_left">
	      <?php echo $this->element('paging_counter'); ?>
		</div>
		<div class="grid_left">
        <?php echo $this->Form->create('ProjectFund' , array('type' => 'get', 'class' => 'normal search-form clearfix','action' => 'index')); ?>
                <?php echo $this->Form->input('q', array('label' => __l('Keyword'))); ?>
        		<?php echo $this->Form->submit(__l('Search'));?>
        <?php echo $this->Form->end(); ?>
        </div>
</div>
<?php Endif; ?>
<table class="list">
    <tr>
	 <th class="actions"><?php echo __l('Action');?></th>
	<?php if(empty($this->request->params['named']['view_type'])) : ?>
        <th class="dl"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Project'),'Project.name');?></div></th>
	<?php endif;?>
		<th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Backer'),'User.username');?></div></th>
        <th><div class="js-pagination"><?php echo __l('Paid Amount') . ' ('.Configure::read('site.currency').')';?></div></th>
        <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Amount to Project Owner'),'amount').' ('.Configure::read('site.currency').')';?></div></th>
        <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Site Commission'), 'site_fee').' ('.Configure::read('site.currency').')';?></div></th>
        <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Pledged On'), 'created');?></div></th>
        <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Status'), 'Status');?></div></th>
        <th class="dl"><div class="js-pagination"><?php echo $this->Paginator->sort('project_reward_id');?></div></th>
    </tr>
<?php
if (!empty($projectFunds)):

$i = 0;
$pledge_amount = $site_fee_amount = $paid_amount = 0;
foreach ($projectFunds as $projectFund):
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
	$pledge_amount += $projectFund['ProjectFund']['amount'] - $projectFund['ProjectFund']['site_fee'];
	$site_fee_amount += $projectFund['ProjectFund']['site_fee'];
	$paid_amount += $projectFund['ProjectFund']['amount'];
?>
	<tr<?php echo $class;?>>
   	<td class="actions dl">
	<?php if ($projectFund['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding && empty($projectFund['ProjectFund']['is_cancelled']) && empty($projectFund['ProjectFund']['is_refunded'])): ?>
            <div class="action-block">
                <span class="action-information-block">
                    <span class="action-left-block">&nbsp;&nbsp;</span>
                        <span class="action-center-block">
                            <span class="action-info">
                                <?php echo __l('Action');?>
                             </span>
                        </span>
                    </span>
                    <div class="action-inner-block">
                    <div class="action-inner-left-block">
                        <ul class="action-link clearfix">
			<li>
				<?php
					echo $this->Html->link(__l('Cancel Pledge'), array('controller' => 'project_funds', 'action' => 'edit_fund', 'project_fund' => $projectFund['ProjectFund']['id'], 'type' => 'cancel', 'return_page' => 'admin', 'admin' => false), array('escape' => false,'class' => 'cancel js-delete', 'title' => __l('Cancel Pledge')));
				?>
			</li>
                  		 </ul>
    					</div>
    					<div class="action-bottom-block"></div>
    				  </div>
              </div>
		<?php endif; ?>
        </td>

		
	<?php if(empty($this->request->params['named']['view_type'])) : ?>
		<td class="dl">
                      <div class="clearfix">
                       <?PHP
                         if($is_wallet_enabled)
                         {
                            $project_status = $projectFund['Project']['ProjectStatus']['name'];
                         }
                           else
                           {
                             $project_status = str_replace("Refunded","Voided",$projectFund['Project']['ProjectStatus']['name']);
                           }
                        ?>
                         <span title="<?php echo $this->Html->cText($project_status,false); ?>" class="project-atatus-info project-status-<?php echo $projectFund['Project']['project_status_id'];?>">
						 <?php echo $this->Html->cText($projectFund['Project']['ProjectStatus']['name']); ?>
                         </span>
						<?php echo $this->Html->link($this->Html->cText($this->Html->truncate($projectFund['Project']['name'],90, array('ending' => '...'))), array('controller'=> 'projects', 'action'=>'view', $projectFund['Project']['slug'],'admin' => false), array('escape' => false,'title'=>$this->Html->cText($projectFund['Project']['name'],false)));?>                         
                        </div>
                    </td>
	<?php endif; ?>
		<td>
                        <?php echo $this->Html->link($this->Html->cText($projectFund['User']['username']), array('controller'=> 'users', 'action'=>'view', $projectFund['User']['username'],'admin' => false), array('escape' => false,'title'=>$this->Html->cText($projectFund['User']['username'],false)));?>
                    </td>
                <td><?php echo $this->Html->cCurrency($projectFund['ProjectFund']['amount']);?></td>

                <td>
                 <?php echo $this->Html->cCurrency($projectFund['ProjectFund']['amount'] - $projectFund['ProjectFund']['site_fee']); ?>
            	 
                </td>
                <td><?php echo $this->Html->cCurrency($projectFund['ProjectFund']['site_fee']);?></td>
               
				
               	<td><?php echo $this->Html->cDateTimeHighlight($projectFund['ProjectFund']['created']);?></td>
			 	
			 	<td>
				<?php
                 $refund = __l('Funded');
					
                        if(($projectFund['ProjectFund']['payment_gateway_id'] == ConstPaymentGateways::PayPal))
						 {
                            if($projectFund['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding)
                               {
                                 $refund = __l('Authorized');
                               }
                               else
                               {
                                 $refund = __l('Captured');
                               }
                        }
                        else
                        {
                             if($projectFund['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding)
                               {
                                 $refund = __l('Pledged');
                               }
                               else
                               {
                                 $refund = __l('Funded');
                               }
                        }
					if(!empty($projectFund['ProjectFund']['is_failed'])) {
						$refund = __l('Failed');
						$class = ' class="altrow hide js-faild"';
					} elseif(!empty($projectFund['ProjectFund']['is_failed'])) {
						$refund = __l('Cancelled');
						$class = ' class="altrow hide js-faild"';
					}elseif(!empty($projectFund['ProjectFund']['is_cancelled'])) {
                       if(($projectFund['ProjectFund']['payment_gateway_id'] == ConstPaymentGateways::PayPal))
						 {
						    $refund = 'Voided';
                         }
                         else
                         {
                            $refund = 'Refunded';
                         }
                         if($projectFund['ProjectFund']['is_canceled_from_paypal'])
                         {
                           $refund.= '(From Paypal)';
                         }
                         $refund = __l($refund);
					}
					echo $refund;
					?>
			</td>
			 	
			 		<td class="dl"><div class="js-truncate"><?php
				if ($projectFund['ProjectFund']['project_reward_id'] == 0) :
					echo __l('n/a');
				else:
					echo Configure::read('site.currency').$this->Html->cText($projectFund['ProjectReward']['pledge_amount']).'+ '.$this->Html->cText($projectFund['ProjectReward']['reward']);
				endif;
				?></div></td>
	</tr>
<?php
    endforeach;
    ?>
    <!--
    <tr>
        <td colspan="<?php echo empty($this->request->params['named']['view_type'])?'6':'5'; ?>"><?php echo __l('Total'); ?></td>
        <td><?php echo $this->Html->cCurrency($pledge_amount); ?></td>
        <td><?php echo $this->Html->cCurrency($site_fee_amount); ?></td>
        <td><?php echo $this->Html->cCurrency($paid_amount); ?></td>
    </tr>-->
    <?php
else:
?>
	<tr>
		<td colspan="9" class="notice"><?php echo __l('No Project Funds available');?></td>
	</tr>
<?php
endif;
?>
</table>
<div class="clearfix">
<?php
if (!empty($projectFunds)) : ?>
<div class="js-pagination grid_right">
   <?php  echo $this->element('paging_links'); ?>
</div>
<?php endif;?>
</div>
</div>